import { Request } from '@/utils';
import httpStatus from '@/utils/enum/httpStatus'
import ResponseFactory, { ResponseFail, ResponseSuccess } from '@/common/responseFactory';
// 创建请求实例
const http: any = Request.getInstance({
    baseUrl: 'http://192.168.31.235:9000/',
    timeout: 1000 * 60, // 1分钟
    isConcat: true, // 断网自动重连
    header: {
        'Content-Type': 'application/x-www-form-urlencoded',
    }
})
// 请求拦截
http.interceptors.request((config: any) => {
    console.log('config', config)
    return config;
})
// 响应拦截
http.interceptors.response((response: any): ResponseFactory => {
    console.log('response', response)
    // 声明响应工厂
    let responseFactory: ResponseFactory;
    if (response.data && response.statusCode == httpStatus.SUCCESS) {
        responseFactory = new ResponseSuccess().response(response.data);
    } else {
        responseFactory = new ResponseFail().response(response);
    }
    return responseFactory;
})
export default http